package cn.fl.system.service.impl;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.system.service.ISysFlowTaskHService;
import cn.fl.system.transform.SysFlowTaskHVOTransform;
import cn.fl.system.vo.SysFlowTaskHVO;
import fl.flow.facade.flow.api.IFlowApiService;
import fl.flow.facade.flow.dto.FlowCompleteParamsDTO;
import fl.flow.facade.flow.dto.SysFlowTaskHDTO;

/**
 * @Description: 流程任务节点操作历史 客户端服务层接口实现
 */
@Service
public class SysFlowTaskHServiceImpl implements ISysFlowTaskHService {

	/**
	 * 日志
	 */
	@SuppressWarnings("unused")
	private static final Logger logger = LoggerFactory.getLogger(SysFlowTaskHServiceImpl.class);
	
	/**
	 * 流程 API暴露服务
	 */
	@Autowired
	private IFlowApiService flowApiService;

	@Override
	public SysFlowTaskHVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id))return null;
		//TODO 业务逻辑
		SysFlowTaskHDTO dto = null;//this.自定义ApiService.selectById(id);
		return SysFlowTaskHVOTransform.toVO(dto);
	}

	@Override
	public DataResultDTO add(SysFlowTaskHVO entity) throws BaseException{
		if(null == entity)return null;
		FlowCompleteParamsDTO flowCompleteParamsDTO = new FlowCompleteParamsDTO();
		flowCompleteParamsDTO.setCrtTm(new Date());
		flowCompleteParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		flowCompleteParamsDTO.setBusinessKey(Long.valueOf(entity.getBusinessKey()));
		flowCompleteParamsDTO.setIsDel(BaseConstant.IS_YESNO_NO);
		flowCompleteParamsDTO.setProcDefId(entity.getProcDefId());
		flowCompleteParamsDTO.setProcDefKey(entity.getProcDefKey());
		flowCompleteParamsDTO.setProcInstId(entity.getProcInstId());
		flowCompleteParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
		flowCompleteParamsDTO.setTaskDefKey(entity.getTaskDefKey());
		flowCompleteParamsDTO.setTaskId(entity.getTaskId());
		flowCompleteParamsDTO.setTaskOpinion(entity.getTaskOpinion());
		flowCompleteParamsDTO.setAttchmntList(entity.getAttchmntList());
		flowCompleteParamsDTO.setBusinessType(entity.getBusinessType());
		return this.flowApiService.addFlowTaskH(flowCompleteParamsDTO);
	}
	
	@Override
	public DataResultDTO addLocal(SysFlowTaskHVO entity) throws BaseException{
		if(null == entity)return null;
		FlowCompleteParamsDTO flowCompleteParamsDTO = new FlowCompleteParamsDTO();
		flowCompleteParamsDTO.setCrtTm(new Date());
		flowCompleteParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		flowCompleteParamsDTO.setBusinessKey(Long.valueOf(entity.getBusinessKey()));
		flowCompleteParamsDTO.setIsDel(BaseConstant.IS_YESNO_NO);
		flowCompleteParamsDTO.setProcDefId(entity.getProcDefId());
		flowCompleteParamsDTO.setProcDefKey(entity.getProcDefKey());
		flowCompleteParamsDTO.setProcInstId(entity.getProcInstId());
		flowCompleteParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
		flowCompleteParamsDTO.setTaskDefKey(entity.getTaskDefKey());
		flowCompleteParamsDTO.setTaskId(entity.getTaskId());
		flowCompleteParamsDTO.setTaskOpinion(entity.getTaskOpinion());
		flowCompleteParamsDTO.setAttchmntList(entity.getAttchmntList());
		flowCompleteParamsDTO.setBusinessType(entity.getBusinessType());
		return this.flowApiService.addFlowTaskHLocal(flowCompleteParamsDTO);
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id))return false;
		//return this.sysFlowTaskHApiService.removeById(id);
		//TODO 业务逻辑
		return false;
	}

	@Override
	public boolean modify(SysFlowTaskHVO entity) throws BaseException{
		if(null == entity)return false;
		//return this.sysFlowTaskHApiService.modify(SysFlowTaskHVOTransform.toDTO(entity));
		//TODO 业务逻辑
		return false;
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		//return this.sysFlowTaskHApiService.searchListPage(page);
		//TODO 业务逻辑
		return null;
	}
}
